define(['jquery','api','user','util'],function($,api,user,util){
	var vm, 
	   controller = {
	   init:function(){
	   	   if(!user.checkLogin())return;
		   api.initFooter(2);
		   api.setTitle('投资学院');
		   if(!vm){
		     this.render();
		   }else{
		     vm.show=true;
		   }
	   },
	   render:function(){
	   	   var that=this;
	   	   $('#pages').append('<div id="article"></div>');
	       require(['text!pages/article/index.html','Vue'],function(tpl,Vue){
	            vm=new Vue({
	               el:'#article',
	               data:{
	               	  show:true,
	               	  articles:{
		              	 1:[],
		              	 2:[],
		              	 3:[]
		              },
	               	  tab:3
	               },
	               filters:{
		              	contentFormat:function(s){
		              		var str=s.replace(/<\/?.+?>/g,"").replace(/&nbsp;/g,"");
		              	    return util.subString(str,70,1);
		              	},
		              	titleFormat:function(v){
		              	     return util.subString(v,35,1);
		              	}
		           },
	               methods:{
	                  switchTab:function(t){
		              	 this.tab=t;
		              }
	               },
	               template:tpl
	            });
	            that.loadNotice();
	            that.loadArticel(1);
	            that.loadArticel(2);
	       })
	   },
	   loadNotice:function(){
	   	   api.noticeList({count:20},function(rs){
	   	       if(rs.retcode==0 && rs.data){
	   	           vm.articles[3]=rs.data;
	   	       }
	   	   })
	   },
	   loadArticel:function(id){
	   	   api.articleList({count:20,typeid:id},function(rs){
	   	       if(rs.retcode==0&&rs.data){
	   	           vm.articles[id]=rs.data;
	   	       }
	   	   })
	   },
	   onRouteChange:function(){
	       if(vm)vm.show=false;
	   }
	}
    return controller;
})